<template>
  <div class="addAddress">
    <van-address-edit :area-list="areaList" show-set-default show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']" save-button-text="确认" @save="onSave" />
  </div>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  import axios from '../../../api/http.js'
  import AreaList from '../../../assets/js/areaList.js'
  export default {
    data() {
      return {
        areaList: AreaList
      }
    },
    methods: {
      async onSave(content) {
        const _this = this
        const params = {
          user_id: _this.loginToken.userId,
          consignee: content.name,
          consignee_phone: content.tel,
          default_flag: content.isDefault === true ? '1' : '0',
          province_name: content.province,
          city_name: content.county,
          region_name: content.city,
          detail_address: content.addressDetail
        }
        await axios.post(axios.defaults.baseURI + 'books/useraddress/', params).then(res => {
          console.log('res:', res)
          if (res.code === 201) {
            this.$toast.success('添加成功！')
            setTimeout(this.$router.go(-1), 400)
          } else {
            this.$toast.fail('添加失败')
          }
        })
        // console.log(content)
      }
    },
    created() {
      console.log('loginToken', this.loginToken)
    },
    computed: {
      ...mapState(['loginToken'])
    }
  }
</script>

<style>
</style>
